package org.study.neo4j.boot;

import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.data.neo4j.repository.config.EnableNeo4jRepositories;
import org.study.neo4j.boot.repository.*;
import org.study.neo4j.boot.service.RelationshipService;

/**
 * 应用程序启动类
 *
 * @author doveylovey
 * @version v1.0.0
 * @email 1135782208@qq.com
 * @date 2025年04月09日
 */
@SpringBootApplication
@EnableNeo4jRepositories(basePackages = {"org.study.neo4j.boot.repository"})
public class Neo4jBootApplication {
    public static void main(String[] args) {
        SpringApplication.run(Neo4jBootApplication.class, args);
    }

    @Bean
    public CommandLineRunner initDatabase(StudentRepository studentRepository,
                                          TeacherRepository teacherRepository,
                                          CourseRepository courseRepository,
                                          RelationshipService relationshipService) {
        return args -> {
            // 清除现有数据
            studentRepository.deleteAll();
            teacherRepository.deleteAll();
            courseRepository.deleteAll();

            /*// 创建教师
            Teacher smith = teacherRepository.save(new Teacher("Smith老师", "计算机科学", "smith@school.edu"));
            Teacher doe = teacherRepository.save(new Teacher("Doe老师", "数学", "doe@school.edu"));

            // 创建学生
            Student alice = studentRepository.save(new Student("学生Alice", 20, "初级"));
            Student bob = studentRepository.save(new Student("学生Bob", 21, "高级"));

            // 创建课程
            Course cs101 = courseRepository.save(new Course("CS101", "编程简介", 3));
            Course math201 = courseRepository.save(new Course("MATH201", "高级微积分", 4));

            // 建立关系
            relationshipService.assignTeacherToCourse(smith.getId(), cs101.getCode());
            relationshipService.assignTeacherToCourse(doe.getId(), math201.getCode());

            relationshipService.enrollStudentInCourse(alice.getId(), cs101.getCode());
            relationshipService.enrollStudentInCourse(alice.getId(), math201.getCode());
            relationshipService.enrollStudentInCourse(bob.getId(), cs101.getCode());

            relationshipService.assignAdvisorToStudent(smith.getId(), alice.getId());
            relationshipService.assignAdvisorToStudent(doe.getId(), bob.getId());*/
        };
    }
}
